<?php
// +----------------------------------------------------------------------
// | 07FLYCRM [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------

namespace app\ten\controller;

use think\db;

/**
 * 用户控制器
 */
class TenTenantType extends TenBase
{
    /**
     * 列表
     */
    public function show()
    {
        return $this->fetch('show');
    }

    /**
     * 列表json数据
     */
    public function show_json()
    {
        $where = [];
        if (!empty($this->param['keywords'])) {
            $where['name|remark'] = ['like', '%' . $this->param['keywords'] . '%'];
        }
        $list = $this->logicTenTenantType->getTenTenantTypeList($where);
        return $list;
    }

    /**
     * 添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicTenTenantType->tenTenantTypeAdd($this->param));
        return $this->fetch('add');
    }

    /**
     * 编辑
     */
    public function edit()
    {
        IS_POST && $this->jump($this->logicTenTenantType->tenTenantTypeEdit($this->param));
        $info = $this->logicTenTenantType->getTenTenantTypeInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch('edit');
    }

    /**
     * 删除
     */
    public function del()
    {
        $where = empty($this->param['id']) ? ['id' => 0] : ['id' => $this->param['id']];
        $this->jump($this->logicTenTenantType->tenTenantTypeDel($where));
    }

    /**
     * 租户类型菜单授权
     */
    public function bindModule()
    {
        IS_POST && $this->jump($this->logicTenTenantType->setTenTenantTypeModules($this->param));
        // 所有模块
        $module_list =$this->logicTenModule->getTenModuleList([], true, 'sort asc', false);

        // 所有模块
        $info = $this->logicTenTenantType->getTenTenantTypeInfo(['id' => $this->param['id']]);

        $module_select_list = $this->logicTenModule->selectModuleList($module_list, $info['module_list']);

        $this->assign('module_select_list', $module_select_list);
        $this->assign('info', $info);
        return $this->fetch('bind_module');
    }
    /**
     * 启用
     */
    public function set_visible()
    {
        $this->jump($this->logicTenBase->setField('TenTenantType', $this->param));
    }
}